package ups.glre.news.dao.impl;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.Query;

import ups.glre.news.dao.NewsDAO;
import ups.glre.news.model.News;

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class NewsDAOImpl extends GenericDAOImpl<News,Integer> implements NewsDAO{

	@SuppressWarnings("unchecked")
	public List<News> findNewsByCategoryId(int categoryId){
		
		Query query = entityManager.createQuery("SELECT e FROM "
				+ entityClass.getName() + " e WHERE categoryId = :categoryId ");
		
		query.setParameter("categoryId", categoryId);
		
		return (List<News>) query.getResultList();
	}
}
